home *** CD-ROM | disk | FTP | other *** search
/ SGI Enlighten DSM 1.1 / SGI EnlightenDSM 1.1.iso / hp10x / emd.z / emd / bin / postinstall_emd < prev    next >
Text File  |  1998-06-30  |  28KB  |  1,101 lines

  1. #!/bin/sh
  2. #
  3. copyright="Copyright (c) 1990-1998 Enlighten Software Solutions, Inc."
  4. #
  5. # Post-installation of EMD and informix
  6. # usage: $0 -f      <informix-DB installation directory> 
  7. #           -emdir  <emd installation directory> 
  8. #           -dbhome <dbenl home>
  9. #           -h displays usagse notes.
  10. #-----------------------------------------------------------------------------
  11. #
  12. # Please note that the 'main' is at the bottom of this script.
  13. # (grep for 'Start')
  14. #
  15.  
  16. # TODO : Remove verbose_output default after debugging is done
  17. #verbose_output="true"
  18.  
  19. #
  20. # Start of functions
  21. #
  22. #
  23.  
  24. display_usage() {
  25.     echo 
  26.     echo "$app_name facilitates post-installation of EMD and informixSE."
  27.     echo 
  28.     echo "Usage: $app_name [-f <informixSE install dir>] \ "
  29.     echo "                       [-emddir <emd installation directory>] \ "
  30.     echo "                       [-dbhome <dbenl home>] \ "
  31.     echo "                       [-help] [-verbose]"
  32.     echo 
  33.     echo "Note: -dbhome defaults to -emddir if no value is given." 
  34.     echo "      -emddir defaults to the emd_dir value stored in /etc/enlighten."
  35.     echo 
  36.     echo $copyright
  37.     echo 
  38. }
  39.  
  40. error_check () {
  41.     if [ $? -ne 0 ] ; then
  42.         echo "$appName: Fatal: Could not successfully finish configuring EMD." 1>&2
  43.         exit 1
  44.     fi
  45. }
  46.  
  47. set_constants () {
  48.  
  49.     # Set umask
  50.  
  51.     umask 077
  52.  
  53.     # Pathnames to EnlightenDSM components
  54.  
  55.     emd_binary=$emd_dir/bin/emdd
  56.     createdb_binary=$emd_dir/bin/CreateDb
  57.     dbaccess_binary=$informix_dir/bin/dbaccess
  58.     createdb_script=$emd_dir/.create_emd_tables.sh
  59.     dbaccess_input=$emd_dir/.dbaccess_input.txt
  60.  
  61.     #
  62.     # These ID numbers are just the starting number - 
  63.     # This script *does* ensure the ID is unique (for local, NIS, and NIS+)
  64.     #
  65.  
  66.     informix_uid=1000
  67.     informix_gid=1000
  68.     informix_home=/
  69.  
  70.     dbenl_uid=1001
  71.  
  72.     ETCPASSWD=/etc/passwd
  73.     ETCSHADOW=/etc/shadow
  74.     ETCGROUP=/etc/group
  75.  
  76.     INFXLIB=iasfs07a.so
  77.  
  78.     case "$os_name" in
  79.         "HP-UX" )
  80.             VSIM=vsifmx7.sl
  81.             ;;
  82.  
  83.         "IRIX64" | "IRIX" | "SunOS" | "AIX" )
  84.             VSIM=vsifmx7.so.1
  85.             ;;
  86.  
  87.         "SCO_SV" ) 
  88.             VSIM=vsifmx5.so.1
  89.             ;;
  90.  
  91.         * )
  92.             echo "$app_name: EMD for $os_name release $os_release is not supported." 1>&2
  93.             exit 2
  94.             ;;
  95.     esac
  96.  
  97.     #
  98.     # Ensure EMD and CreateDb have a log directory to write to
  99.     #
  100.  
  101.     if [ ! -d $emd_dir/logs ] ; then
  102.         mkdir -p $emd_dir/logs
  103.         chmod 700 $emd_dir/logs
  104.         error_check
  105.     fi
  106.  
  107.     #-----------------------------------------------------------------------------
  108.     #
  109.     # Determine if NIS or NIS+ is running
  110.     #
  111.  
  112.     unset nis_running
  113.  
  114.     if [ -n "`ps $ps_opts | grep ypbind | grep -v grep`" ] ; then
  115.  
  116.         #
  117.         # Ensure NIS is actually up and functional
  118.         #
  119.  
  120.         ypcat passwd 2> /dev/null > $ypcat_passwd_output 
  121.  
  122.         if [ $? -ne 0 ] ; then
  123.             echo "$app_name: Host was found to be running ypbind, but 'ypcat passwd' failed."
  124.         else
  125.  
  126.             ypcat group 2> /dev/null > $ypcat_group_output 
  127.  
  128.             if [ $? -ne 0 ] ; then
  129.                 echo "$app_name: Host was found to be running ypbind, but 'ypcat group' failed."
  130.             else
  131.  
  132.                 nis_running="true"
  133.                 if [ "$verbose_output" ] ; then
  134.                     echo "$app_name: Host was found to be using NIS."
  135.                 fi
  136.             fi
  137.         fi
  138.     fi
  139.  
  140.     if [ -n "`ps $ps_opts | grep nis_cach | grep -v grep`" ] ; then
  141.  
  142.         #
  143.         # Ensure NIS+ is actually up and functional
  144.         #
  145.  
  146.         niscat passwd.org_dir 2> /dev/null > $niscat_passwd_output 
  147.  
  148.         if [ $? -ne 0 ] ; then
  149.             echo "$app_name: The NIS+ client daemon was up, but 'niscat passwd.org_dir' failed."
  150.         else
  151.  
  152.             niscat group.org_dir 2> /dev/null > $niscat_group_output 
  153.  
  154.             if [ $? -ne 0 ] ; then
  155.                 echo "$app_name: The NIS+ client daemon was up, but 'niscat group.org_dir' failed."
  156.             else
  157.  
  158.                 nis_plus_running="true"
  159.                 if [ "$verbose_output" ] ; then
  160.                     echo "$app_name: Host was found to be using NIS."
  161.                 fi
  162.             fi
  163.         fi
  164.     fi
  165.  
  166.     #-----------------------------------------------------------------------------
  167.     #
  168.     # Workaround for IRIX (and possibly other OSes).
  169.     #
  170.     # Informix gives a "25590: Authentication error." when the dbenl user
  171.     # or informix user is not in the local /etc/passwd file.
  172.     #
  173.  
  174.     force_local_dbenl_user="true"
  175.  
  176. }
  177.  
  178. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  179. #          Add group 'informix', user 'informix', and user 'dbenl'.
  180. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  181.  
  182. add_informix_group () {
  183.  
  184.     #-----------------------------------------------------------------------------
  185.     #
  186.     # See if group 'informix' is defined
  187.     #
  188.  
  189.     unset informix_group_exists
  190.  
  191.     if [ -n "`grep '^informix:' $ETCGROUP`" ] ; then
  192.  
  193.         informix_group_exists="true"
  194.         informix_gid=`grep "^informix:" $ETCGROUP | cut '-d:' -f3`
  195.  
  196.         if [ "$verbose_output" ] ; then
  197.             echo $app_name": group 'informix' (gid=$informix_gid) is already in $ETCGROUP"
  198.         fi
  199.  
  200.     elif [ -z "$force_local_informix_group" -a "$nis_running" ] ; then
  201.         if [ -n "`grep '^informix:' $ypcat_group_output`" ] ; then
  202.  
  203.             informix_group_exists="true"
  204.             informix_gid=`grep "^informix:" $ypcat_group_output | cut '-d:' -f3`
  205.  
  206.             if [ "$verbose_output" ] ; then
  207.                 echo "$app_name: group 'informix' (gid=$informix_gid) is already in NIS."
  208.             fi
  209.  
  210.         fi
  211.  
  212.     elif [ -z "$force_local_informix_group" -a "$nis_plus_running" ] ; then
  213.         if [ -n "`grep '^informix:' $niscat_group_output`" ] ; then
  214.  
  215.             informix_group_exists="true"
  216.             informix_gid=`grep "^informix:" $niscat_group_output | cut '-d:' -f3`
  217.  
  218.             if [ "$verbose_output" ] ; then
  219.                 echo "$app_name: group 'informix' (gid=$informix_gid) is already in NIS+."
  220.             fi
  221.  
  222.         fi
  223.  
  224.     elif [ "$verbose_output" ] ; then
  225.         echo "$app_name: Group 'informix' does not exist."
  226.     fi
  227.         
  228.     #-----------------------------------------------------------------------------
  229.     #
  230.     # Create the 'informix' group if necessary
  231.     #
  232.  
  233.     if [ ! "$informix_group_exists" ] ; then
  234.  
  235.         #
  236.         # Make a temporary file with all the current gid #s
  237.         # (using a temp file lets me only call ypcat or niscat once.)
  238.         #
  239.  
  240.         cut '-d:' -f3 $ETCGROUP > $temp_file
  241.         error_check
  242.         if [ "$nis_running" ] ; then
  243.             cat $ypcat_group_output | cut '-d:' -f3 >> $temp_file
  244.             error_check
  245.         fi
  246.         if [ "$nis_plus_running" ] ; then
  247.             cat $niscat_group_output | cut '-d:' -f3 >> $temp_file
  248.             error_check
  249.         fi
  250.  
  251.         # Now search through that file to find a unique id.
  252.  
  253.         while [ -n "`fgrep -x $informix_gid $temp_file`" ] ; do
  254.             if [ "$verbose_output" ] ; then
  255.                 echo "$app_name: 'informix' gid $informix_gid was not unique."
  256.             fi
  257.             informix_gid=`expr 1 + $informix_gid`
  258.         done
  259.  
  260.         if [ "$verbose_output" ] ; then
  261.             echo "$app_name: 'informix' gid $informix_gid was found to be unique."
  262.         fi
  263.  
  264.         # Backup $ETCGROUP 
  265.  
  266.         cp $ETCGROUP $ETCGROUP.orig
  267.         echo "$app_name: $ETCGROUP was archived to $ETCGROUP.orig"
  268.  
  269.         # And add the entry to the start of $ETCGROUP
  270.  
  271.         rm -f $temp_file
  272.         error_check
  273.  
  274.         lineno=`grep -n "^+" $ETCGROUP | awk -F: '{print $1}'` 
  275.      
  276.         if [ $lineno ] ; then
  277.             sed -e ''${lineno}'i\
  278. informix::'${informix_gid}':informix' $ETCGROUP > $temp_file
  279.             error_check
  280.         else
  281.             cat $ETCGROUP > $temp_file
  282.             error_check
  283.             echo 'informix::'${informix_gid}':informix' >> $temp_file
  284.             error_check
  285.         fi
  286.  
  287.         if [ "$verbose_output" ] ; then
  288.             echo "$app_name: Moving the new group file into $ETCGROUP..."
  289.         fi
  290.         cp $temp_file $ETCGROUP
  291.         error_check
  292.  
  293.         chmod 644 $ETCGROUP
  294.         error_check
  295.         rm -f $temp_file
  296.         error_check
  297.  
  298.         echo "$app_name: Group 'informix' (gid=$informix_gid) was added successfully."
  299.  
  300.     fi
  301.  
  302. }
  303.  
  304. add_informix_user () {
  305.  
  306.     #-----------------------------------------------------------------------------
  307.     #
  308.     # See if user 'informix' is defined
  309.     #
  310.  
  311.     unset informix_user_exists
  312.  
  313.     if [ -n "`grep '^informix:' $ETCPASSWD`" ] ; then
  314.  
  315.         informix_user_exists="true"
  316.  
  317.         if [ "$verbose_output" ] ; then
  318.             echo $app_name": User 'informix' is already in $ETCPASSWD"
  319.         fi
  320.  
  321.     elif [ -z "$force_local_informix_user" -a "$nis_running" ] ; then
  322.         if [ -n "`grep '^informix:' $ypcat_passwd_output`" ] ; then
  323.  
  324.             informix_user_exists="true"
  325.  
  326.             if [ "$verbose_output" ] ; then
  327.                 echo "$app_name: User 'informix' is already in NIS"
  328.             fi
  329.  
  330.         fi
  331.  
  332.     elif [ -z "$force_local_informix_user" -a "$nis_plus_running" ] ; then
  333.         if [ -n "`grep '^informix:' $niscat_passwd_output`" ] ; then
  334.  
  335.             informix_user_exists="true"
  336.  
  337.             if [ "$verbose_output" ] ; then
  338.                 echo "$app_name: User 'informix' is already in NIS+"
  339.             fi
  340.  
  341.         fi
  342.  
  343.     elif [ "$verbose_output" ] ; then
  344.         echo "$app_name: User 'informix' does not exist."
  345.     fi
  346.         
  347.     #-----------------------------------------------------------------------------
  348.     #
  349.     # Create the 'informix' user account if necessary
  350.     #
  351.  
  352.     if [ ! "$informix_user_exists" ] ; then
  353.  
  354.         #
  355.         # Make a temporary file with all the current gid #s
  356.         # (using a temp file lets me only call ypcat or niscat once.)
  357.         #
  358.  
  359.         cut '-d:' -f3 $ETCPASSWD > $temp_file
  360.         error_check
  361.         if [ "$nis_running" ] ; then
  362.             cat $ypcat_passwd_output | cut '-d:' -f3 >> $temp_file
  363.             error_check
  364.         fi
  365.         if [ "$nis_plus_running" ] ; then
  366.             cat $niscat_passwd_output | cut '-d:' -f3 >> $temp_file
  367.             error_check
  368.         fi
  369.  
  370.         # Now search through that file to find a unique id.
  371.  
  372.         while [ -n "`fgrep -x $informix_uid $temp_file`" ] ; do
  373.             if [ "$verbose_output" ] ; then
  374.                 echo "$app_name: 'informix' uid $informix_uid was not unique."
  375.             fi
  376.             informix_uid=`expr 1 + $informix_uid`
  377.         done
  378.  
  379.         if [ "$verbose_output" ] ; then
  380.             echo "$app_name: 'informix' uid $informix_uid was found to be unique."
  381.         fi
  382.  
  383.         # Backup $ETCPASSWD 
  384.  
  385.         cp $ETCPASSWD $ETCPASSWD.orig
  386.         echo "$app_name: $ETCPASSWD was archived to $ETCPASSWD.orig"
  387.  
  388.         # Make 'informix' such that only root can su informix
  389.  
  390.         if [ "$os_name" = "AIX" -a -f /etc/security/passwd ] ; then
  391.             echo "informix:\!:$informix_uid:$informix_gid:Informix user:$informix_home:/bin/sh" \
  392.                 > $temp_file
  393.             error_check
  394.  
  395.         elif [ -f $ETCSHADOW ] ; then
  396.             echo "informix:x:$informix_uid:$informix_gid:Informix user:$informix_home:/bin/sh" \
  397.                 > $temp_file
  398.             error_check
  399.  
  400.         else
  401.             echo "informix:*:$informix_uid:$informix_gid:Informix user:$informix_home:/bin/sh" \
  402.                 > $temp_file
  403.             error_check
  404.         fi
  405.  
  406.         cat $ETCPASSWD >> $temp_file
  407.         error_check
  408.  
  409.         if [ "$verbose_output" ] ; then
  410.             echo "$app_name: Moving the new passwd file into $ETCPASSWD..."
  411.         fi
  412.         cp $temp_file $ETCPASSWD
  413.         error_check
  414.  
  415.         chmod 644 $ETCPASSWD
  416.         error_check
  417.  
  418.         rm -f $temp_file
  419.  
  420.         # Add the reference to the security file/shadow file
  421.  
  422.         if [ "$os_name" = "AIX" -a -f /etc/security/passwd ] ; then
  423.  
  424.             # Backup /etc/security/passwd
  425.  
  426.             cp /etc/security/passwd /etc/security/passwd.orig
  427.             error_check
  428.             echo "$app_name: /etc/security/passwd was archived to /etc/security/passwd.orig"
  429.  
  430.             # Add the passwd entry
  431.  
  432.             echo "informix:\n\tpassword = *\n" > $temp_file
  433.             error_check
  434.  
  435.             cat /etc/security/passwd >> $temp_file
  436.             error_check
  437.  
  438.             if [ "$verbose_output" ] ; then
  439.                 echo "$app_name: Copying in the new /etc/security/passwd file..."
  440.             fi
  441.  
  442.             cp $temp_file /etc/security/passwd
  443.             error_check
  444.  
  445.             if [ "$verbose_output" ] ; then
  446.                 echo $app_name": AIX user 'informix' added to /etc/security/passwd."
  447.             fi
  448.             rm -f $temp_file
  449.  
  450.         elif [ -f $ETCSHADOW ] ; then
  451.  
  452.             # Backup /etc/shadow
  453.             cp -p $ETCSHADOW $ETCSHADOW.orig
  454.             error_check
  455.             echo "$app_name: $ETCSHADOW was archived to $ETCSHADOW.orig"
  456.  
  457.             # Add the passwd entry
  458.  
  459.             echo "informix:*:::" > $temp_file
  460.             error_check
  461.             cat $ETCSHADOW >> $temp_file
  462.             error_check
  463.  
  464.             cp $temp_file $ETCSHADOW
  465.             error_check
  466.  
  467.             if [ "$verbose_output" ] ; then
  468.                 echo "$app_name: user 'informix' added to $ETCSHADOW."
  469.             fi
  470.             rm -f $temp_file
  471.  
  472.         fi
  473.  
  474.         echo $app_name": User 'informix' (uid="$informix_uid") added successfully."
  475.  
  476.     fi
  477. }
  478.  
  479. add_dbenl_user () {
  480.  
  481.     #-----------------------------------------------------------------------------
  482.     #
  483.     # See if user 'dbenl' is defined
  484.     #
  485.  
  486.     unset dbenl_user_exists
  487.  
  488.     if [ -n "`grep '^dbenl:' $ETCPASSWD`" ] ; then
  489.  
  490.         dbenl_user_exists="true"
  491.  
  492.         if [ "$verbose_output" ] ; then
  493.             echo $app_name": User 'dbenl' is already in $ETCPASSWD"
  494.         fi
  495.  
  496.         old_dbenl_home_dir=`grep "^dbenl:" $ETCPASSWD | cut '-d:' -f6`
  497.  
  498.     elif [ -z "$force_local_dbenl_user" -a "$nis_running" ] ; then
  499.         if [ -n "`grep '^dbenl:' $ypcat_passwd_output" ] ; then
  500.  
  501.             dbenl_user_exists="true"
  502.  
  503.             if [ "$verbose_output" ] ; then
  504.                 echo "$app_name: User 'dbenl' is already in NIS"
  505.             fi
  506.  
  507.             old_dbenl_home_dir=`grep "^dbenl:" $ypcat_passwd_output | cut '-d:' -f6`
  508.         fi
  509.  
  510.     elif [ -z "$force_local_dbenl_user" -a "$nis_plus_running" ] ; then
  511.         if [ -n "`grep '^dbenl:' $niscat_passwd_output`" ] ; then
  512.  
  513.             dbenl_user_exists="true"
  514.  
  515.             if [ "$verbose_output" ] ; then
  516.                 echo "$app_name: User 'dbenl' is already in NIS+"
  517.             fi
  518.  
  519.             old_dbenl_home_dir=`grep "^dbenl:" $niscat_passwd_output | cut '-d:' -f6`
  520.         fi
  521.  
  522.     elif [ "$verbose_output" ] ; then
  523.         echo "$app_name: User 'dbenl' does not exist."
  524.     fi
  525.         
  526.     if [ -n "$old_dbenl_home_dir" -a ! "$old_dbenl_home_dir" = "$emd_dir" ] ; then
  527.  
  528.         #
  529.         # TODO: Upgrade code goes here. (Dump table, change dbenl_home 
  530.         # entry is in /etc/passwd, and import table.)
  531.         #
  532.  
  533.         echo "$app_name: A previously existing 'dbenl' home directory points to $old_dbenl_home_dir." 1>&2
  534.         echo "$app_name: Please deinstall on this host before reinstalling EMD." 1>&2
  535.         exit 1
  536.     fi
  537.  
  538.     #-----------------------------------------------------------------------------
  539.     #
  540.     # Create the 'dbenl' user account if necessary
  541.     #
  542.  
  543.     if [ ! "$dbenl_user_exists" ] ; then
  544.  
  545.         #
  546.         # Make a temporary file with all the current gid #s
  547.         # (using a temp file lets me only call ypcat or niscat once.)
  548.         #
  549.  
  550.         cut '-d:' -f3 $ETCPASSWD > $temp_file
  551.         error_check
  552.  
  553.         if [ "$nis_running" ] ; then
  554.             cat $ypcat_passwd_output | cut '-d:' -f3 >> $temp_file
  555.             error_check
  556.         fi
  557.         if [ "$nis_plus_running" ] ; then
  558.             cat $niscat_passwd_output | cut '-d:' -f3 >> $temp_file
  559.             error_check
  560.         fi
  561.  
  562.         # Now search through that file to find a unique id.
  563.  
  564.         while [ -n "`fgrep -x $dbenl_uid $temp_file`" ] ; do
  565.             if [ "$verbose_output" ] ; then
  566.                 echo "$app_name: 'dbenl' uid $dbenl_uid was not unique."
  567.             fi
  568.             dbenl_uid=`expr 1 + $dbenl_uid`
  569.         done
  570.  
  571.         if [ "$verbose_output" ] ; then
  572.             echo "$app_name: 'dbenl' uid $dbenl_uid was found to be unique."
  573.         fi
  574.  
  575.         # Backup $ETCPASSWD 
  576.  
  577.         cp $ETCPASSWD $ETCPASSWD.orig
  578.         echo "$app_name: $ETCPASSWD was archived to '$ETCPASSWD.orig'"
  579.  
  580.         # Make 'dbenl' such that only root can su dbenl
  581.  
  582.         if [ "$os_name" = "AIX" -a -f /etc/security/passwd ] ; then
  583.             echo "dbenl:\!:$dbenl_uid:$informix_gid:Informix user:$dbenl_home:/bin/sh" \
  584.                 > $temp_file
  585.             error_check
  586.  
  587.         elif [ -f $ETCSHADOW ] ; then
  588.             echo "dbenl:x:$dbenl_uid:$informix_gid:Informix user:$dbenl_home:/bin/sh" \
  589.                 > $temp_file
  590.             error_check
  591.  
  592.         else
  593.             echo "dbenl:*:$dbenl_uid:$informix_gid:Informix user:$dbenl_home:/bin/sh" \
  594.                 > $temp_file
  595.             error_check
  596.         fi
  597.  
  598.         cat $ETCPASSWD >> $temp_file
  599.         error_check
  600.  
  601.         if [ "$verbose_output" ] ; then
  602.             echo "$app_name: Moving the new passwd file into $ETCPASSWD..."
  603.         fi
  604.         cp $temp_file $ETCPASSWD
  605.         error_check
  606.  
  607.         chmod 644 $ETCPASSWD
  608.         error_check
  609.  
  610.         rm -f $temp_file
  611.  
  612.         # Add the reference to the security file/shadow file
  613.  
  614.         if [ "$os_name" = "AIX" -a -f /etc/security/passwd ] ; then
  615.  
  616.             # Backup /etc/security/passwd
  617.  
  618.             cp /etc/security/passwd /etc/security/passwd.orig
  619.             error_check
  620.             echo "$app_name: /etc/security/passwd was archived to /etc/security/passwd.orig"
  621.  
  622.             # Add the passwd entry
  623.  
  624.             echo "dbenl:\n\tpassword = *\n" > $temp_file
  625.             error_check
  626.  
  627.             cat /etc/security/passwd >> $temp_file
  628.             error_check
  629.  
  630.             if [ "$verbose_output" ] ; then
  631.                 echo "$app_name: Copying in the new /etc/security/passwd file..."
  632.             fi
  633.  
  634.             cp $temp_file /etc/security/passwd
  635.             error_check
  636.  
  637.             if [ "$verbose_output" ] ; then
  638.                 echo $app_name": AIX user 'dbenl' added to /etc/security/passwd."
  639.             fi
  640.             rm -f $temp_file
  641.  
  642.         elif [ -f $ETCSHADOW ] ; then
  643.  
  644.             # Backup /etc/shadow
  645.  
  646.             cp -p $ETCSHADOW $ETCSHADOW.orig
  647.             error_check
  648.             echo "$app_name: $ETCSHADOW was archived to $ETCSHADOW.orig"
  649.  
  650.             # Add the passwd entry
  651.  
  652.             echo "dbenl:*:::" > $temp_file
  653.             error_check
  654.             cat $ETCSHADOW >> $temp_file
  655.             error_check
  656.  
  657.             cp $temp_file $ETCSHADOW
  658.             error_check
  659.  
  660.             if [ "$verbose_output" ] ; then
  661.                 echo "$app_name: user 'dbenl' added to $ETCSHADOW."
  662.             fi
  663.             rm -f $temp_file
  664.  
  665.         fi
  666.  
  667.         echo $app_name": User 'dbenl' (uid="$dbenl_uid") added successfully."
  668.  
  669.     fi
  670. }
  671.  
  672. create_emd_database () {
  673.  
  674.     #-----------------------------------------------------------------------------
  675.     #
  676.     # Misc. permissions changing to dbenl and informix.
  677.     # Also get rid of old tables if they exist.
  678.     #
  679.  
  680.     if [ ! -d $emd_dir/dbtables ] ; then
  681.         mkdir $emd_dir/dbtables
  682.         chmod 700 $emd_dir/dbtables
  683.         error_check
  684.     fi
  685.  
  686.     if [ -d ${emd_dir}/dbtables/enlighten.dbs ] ; then
  687.         rm -fr ${emd_dir}/dbtables/enlighten.dbs
  688.     fi
  689.  
  690.     if [ -f ${emd_dir}/dbtables/enlighten.log ] ; then
  691.         rm ${emd_dir}/dbtables/enlighten.log
  692.     fi
  693.  
  694.     if [ ! -d $informix_dir ] ; then
  695.         echo "The Informix directory, $informix_dir, was missing." 1>&2
  696.         exit 3
  697.     fi
  698.  
  699.     if [ ! -d $emd_dir/odbc ] ; then
  700.         echo "The odbc directory, $emd_dir/odbc, was missing." 1>&2
  701.         exit 3
  702.     fi
  703.  
  704.     if [ ! -x $emd_binary ] ; then
  705.         if [ -f $emd_binary ] ; then
  706.             chmod u+x $emd_binary
  707.         else
  708.             echo "The EMD daemon, $emd_binary, was missing." 1>&2
  709.             exit 3
  710.         fi
  711.     fi 
  712.  
  713.     if [ ! -x $createdb_binary ] ; then
  714.         if [ -f $createdb_binary ] ; then
  715.             chmod u+x $createdb_binary
  716.         else
  717.             echo "The CreateDb utility, $createdb_binary, was missing." 1>&2
  718.             exit 3
  719.         fi
  720.     fi
  721.  
  722.     chown -R dbenl $emd_dir
  723.     error_check
  724.  
  725.     chown -R informix $informix_dir
  726.     error_check
  727.  
  728.     chgrp -R informix $informix_dir
  729.     error_check
  730.  
  731.     #-----------------------------------------------------------------------------
  732.  
  733.     if [ -f $informix_dir/etc/sqlhosts ] ; then
  734.         echo "enl_se seipcpip `uname -n` sqlexec" > $temp_file
  735.         error_check
  736.         cat $informix_dir/etc/sqlhosts | grep -v enl_se >> $temp_file    
  737.         error_check
  738.         cp $temp_file $informix_dir/etc/sqlhosts
  739.         error_check
  740.         rm -f $temp_file
  741.     fi
  742.  
  743.     case "$os_name" in  
  744.         "SunOS" )
  745.             if [ -f $informix_dir/lib/$INFXLIB ] ; then
  746.  
  747.                 if [ -f /usr/lib/$INFXLIB ] ; then
  748.                     rm -f /usr/lib/$INFXLIB
  749.                     error_check
  750.                 fi
  751.  
  752.                 cp $informix_dir/lib/$INFXLIB /usr/lib
  753.                 error_check
  754.                 chmod a+r /usr/lib/$INFXLIB
  755.                 error_check
  756.             else
  757.                 echo "The Informix library, $informix_dir/lib/$INFXLIB, was not found." 1>&2
  758.             fi
  759.             ;;
  760.         "AIX" )
  761.             for i in libasf.o netlib.o netstub.o libgen.o libos.o libsql.o ; do
  762.                 if [ ! -f /usr/lib/$i ] ; then
  763.                     cp $emd_dir/odbc/lib/$i /usr/lib
  764.                     error_check
  765.                     chmod a+r /usr/lib/$i
  766.                     error_check
  767.                 fi
  768.             done
  769.             ;;
  770.         * )
  771.             ;;
  772.     esac
  773.  
  774.     #-----------------------------------------------------------------------------
  775.     # setup the odbc.ini file
  776.  
  777.     if [ -f $dbenl_home/.odbc.ini ] ; then
  778.         mv $dbenl_home/.odbc.ini $dbenl_home/.odbc.ini.orig
  779.     fi
  780.  
  781.     echo "[ODBC Data Source]"                         >  $dbenl_home/.odbc.ini
  782.     echo "enl-informix=Informix Driver for Enlighten" >> $dbenl_home/.odbc.ini
  783.     echo                                              >> $dbenl_home/.odbc.ini
  784.     echo "[ODBC]"                                     >> $dbenl_home/.odbc.ini
  785.     echo "Trace=0"                                    >> $dbenl_home/.odbc.ini
  786.     echo "InstallDir=$emd_dir/odbc"                   >> $dbenl_home/.odbc.ini
  787.     echo                                              >> $dbenl_home/.odbc.ini
  788.     echo "[enl-informix]"                             >> $dbenl_home/.odbc.ini
  789.     echo "Driver=$emd_dir/odbc/drivers/$VSIM"         >> $dbenl_home/.odbc.ini
  790.     echo "Database=enlighten"                         >> $dbenl_home/.odbc.ini
  791.  
  792.     chown dbenl $dbenl_home/.odbc.ini
  793.     chmod 700 $dbenl_home/.odbc.ini
  794.  
  795.     #-----------------------------------------------------------------------------
  796.     # setup the .profile
  797.  
  798.     if [ -f $dbenl_home/.profile ] ; then
  799.         mv $dbenl_home/.profile $dbenl_home/.profile.orig
  800.         echo "$app_name: $dbenl_home/.profile was archived to $dbenl_home/.profile.orig."
  801.     fi
  802.  
  803.     # assign $library_path_name and get the environment variable's setting - 
  804.     # and if it isn't set, default to "/usr/lib".
  805.  
  806.     case "$os_name" in 
  807.         "HP-UX" )
  808.             libpath_name="SHLIB_PATH"
  809.             libpath=${SHLIB_PATH:-"/usr/lib"}
  810.             ;;
  811.         "IRIX64" )
  812.             libpath_name="LD_LIBRARY_PATH"
  813.             libpath=${LD_LIBRARY_PATH:-""}
  814.             ;;
  815.         "IRIX" | "SunOS" | "SCO_SV" )
  816.             libpath_name="LD_LIBRARY_PATH"
  817.             libpath=${LD_LIBRARY_PATH:-"/usr/lib"}
  818.             ;;
  819.         "AIX" )
  820.             libpath_name="LIBPATH"
  821.             libpath=${LIBPATH:-"/usr/lib"}
  822.             ;;
  823.         * )
  824.             echo "$app_name: No $library_path_name was defined."
  825.             ;;
  826.     esac
  827.  
  828.     libpath=$emd_dir/odbc/lib:$informix_dir/lib:$libpath
  829.  
  830.     echo "umask 077"                                         > $dbenl_home/.profile
  831.     echo "emd_dir=$emd_dir"                                  >> $dbenl_home/.profile
  832.     echo "DBPATH=$emd_dir/dbtables ; export DBPATH"          >> $dbenl_home/.profile
  833.     echo "INFORMIXDIR=$informix_dir ; export INFORMIXDIR"    >> $dbenl_home/.profile
  834.     echo "INFORMIXSERVER=enl_se ; export INFORMIXSERVER"     >> $dbenl_home/.profile
  835.     echo "ODBC=$emd_dir/odbc ; export ODBC"          >> $dbenl_home/.profile
  836.     echo "LM_LICENSE_FILE=$emd_dir/FLEXlm/license.dat ; export LM_LICENSE_FILE"  >> $dbenl_home/.profile
  837.     echo "HOME=$dbenl_home ; export HOME"                    >> $dbenl_home/.profile
  838.     echo "PATH=$informix_dir/bin:$PATH ; export PATH"        >> $dbenl_home/.profile
  839.     echo "$libpath_name=$libpath ; export $libpath_name"     >> $dbenl_home/.profile
  840.     echo "ENL_MCAT_DIR=$emd_dir/msg/C ; export ENL_MCAT_DIR" >> $dbenl_home/.profile
  841.  
  842.     # ensure that dbaccess will run on IRIX
  843.     if [ "$os_name" = "IRIX" -o "$os_name" = "IRIX64" ]
  844.     then
  845.         echo "TERMCAP=$dbenl_home/informix/etc/termcap ; export TERMCAP" >> $dbenl_home/.profile
  846.         echo "TERM=vt100 ; export TERM" >> $dbenl_home/.profile
  847.     fi
  848.  
  849.     chown dbenl $dbenl_home/.profile
  850.     chmod 700 $dbenl_home/.profile
  851.  
  852.     echo "create database enlighten" > $dbaccess_input
  853.     error_check
  854.  
  855.     echo "cd $emd_dir/dbtables" > $createdb_script
  856.     echo "$dbaccess_binary - - < $dbaccess_input" >> $createdb_script
  857.  
  858.     #
  859.     # The AIX and IRIX dbaccess has a bug which leaves .seuser corrupt 
  860.     # after it creates and writes to a db.
  861.     #
  862.     # The solution is to cat /dev/null into the  $informix_dir/etc/.seuser file
  863.     # after dbaccess runs (and before createdb runs).
  864.     # If the database is created without logging enabled, then this bug appears
  865.     # anytime you disconnect from the database on IRIX only. So clear the file 
  866.     # again after running CreateDb and after importing old database. 
  867.     #
  868.  
  869.     case "$os_name" in
  870.         "AIX" | "IRIX" | "IRIX64" )
  871.             echo "cat /dev/null > $informix_dir/etc/.seuser" >> $createdb_script
  872.             ;;
  873.         * )
  874.             ;;
  875.     esac
  876.  
  877.     echo "cd $emd_dir/dbtables" >> $createdb_script
  878.     echo "$createdb_binary `uname -n` $upgrade" >> $createdb_script
  879.     case "$os_name" in
  880.          "IRIX" | "IRIX64" )
  881.             echo "cat /dev/null > $informix_dir/etc/.seuser" >> $createdb_script
  882.             ;;
  883.         * )
  884.             ;;
  885.     esac
  886.  
  887.     echo "exit" >> $createdb_script
  888.  
  889.     chown dbenl $createdb_script $dbaccess_input
  890.     chmod 700 $createdb_script
  891.     chmod 400 $dbaccess_input
  892.  
  893.     export emd_dir createdb_script
  894.  
  895.     ( su - dbenl -c $createdb_script > $emd_dir/logs/createdb.log ) 2> $emd_dir/logs/createdb.err  
  896.  
  897.     #
  898.     # If 'Database created' is in createdb.err, all is good.
  899.     #
  900.  
  901.     if [ -f $emd_dir/logs/createdb.err ] ; then
  902.         if [ "`grep '^Database created\.' $emd_dir/logs/createdb.err`" -a \
  903.             ! "`grep '{error}' $emd_dir/logs/createdb.err`" ] ; then
  904.             cat $emd_dir/logs/createdb.err >> $emd_dir/logs/createdb.log
  905.             rm $emd_dir/logs/createdb.err
  906.             # Well, at least the DB was initialized okay...
  907.         else
  908.             echo "$app_name: Errors occurred while creating the dbtables:" 1>&2 
  909.             cat $emd_dir/logs/createdb.err 1>&2
  910.             exit_code=1
  911.         fi
  912.     fi
  913.  
  914.     #
  915.     # Make sure CreateDb was all good
  916.     #
  917.  
  918.     if [ -f $emd_dir/dbtables/install.log ] ; then
  919.         if [ -n "`fgrep 'Table creations successfully completed' $emd_dir/dbtables/install.log`" ] ; then
  920.             echo "$app_name: The EMD database was successfully created."
  921.         else
  922.             echo "$app_name: Errors occurred from $createdb_binary:" 1>&2 
  923.             cat $emd_dir/dbtables/install.log 1>&2
  924.             exit_code=1
  925.         fi
  926.     else
  927.         echo "$app_name: $createdb_binary was not run properly." 1>&2 
  928.         exit_code=1
  929.     fi
  930.  
  931.     #
  932.     # Reimport data from previous database if upgrade flag = 1
  933.     #
  934.  
  935.     if [ "$upgrade" -eq 1 ] ; then
  936.         if [ ! -d ${emd_dir}/dbtables/enlighten.exp ] ; then
  937.             echo "$app_name: Unable to find enlighten.exp directory." 1>&2
  938.             echo "$app_name: Unable to restore EMD data." 1>&2
  939.             exit_code=1
  940.         fi
  941.  
  942.     #
  943.     # Determine which dbload commands file to use. This depends on whether
  944.     # the exported database was using logging or not. The names of the 
  945.     # exported files helps us deermine this
  946.     #
  947.  
  948.         if [ -f ${emd_dir}/dbtables/enlighten.exp/pool_tb100.unl ] ; then
  949.             cmds_file="emd_dbload_cmds.nolog"
  950.         elif [ -f ${emd_dir}/dbtables/enlighten.exp/pool_tb101.unl ] ; then
  951.             cmds_file="emd_dbload_cmds"
  952.         else
  953.             cmds_file=""
  954.             echo "$app_name: Unable to determine which cmds file to use." 1>&2
  955.             echo "$app_name: Unable to restore EMD data." 1>&2
  956.             exit_code=1
  957.         fi
  958.  
  959.         if [ ! -f ${emd_dir}/bin/${cmds_file} ] ; then
  960.             echo "$app_name: Unable to find $cmds_file file." 1>&2
  961.             echo "$app_name: Unable to restore EMD data." 1>&2
  962.             exit_code=1
  963.         fi
  964.  
  965.         if [ "$exit_code" -ne 1 ] ; then    
  966.             chmod u+w ${emd_dir}/dbtables/enlighten.exp
  967.             cp ${emd_dir}/bin/${cmds_file} ${emd_dir}/dbtables/enlighten.exp
  968.             chmod 500 ${emd_dir}/dbtables/enlighten.exp/${cmds_file}
  969.             su dbenl -c "cd ${emd_dir} ; . ./.profile; cd dbtables/enlighten.exp; dbload -c ${cmds_file} -d enlighten -l enl_dbload.log -e 100 1> tmp "         
  970.             res=`echo $?`
  971.             if [ "${res}" -gt 0 ] ; then
  972.                  echo "$app_name: Errors occured while restoring EMD data." 1>&2
  973.                  echo "$app_name: See ${emd_dir}/dbtables/enlighten.exp/enl_dbload.log for details." 1>&2
  974.                 exit_code=1
  975.             else
  976.                 echo "$app_name: Successfully restored EMD data."
  977.             fi    
  978.             # Take care of that irix bug that corrupts the .seuser file
  979.             case "$os_name" in
  980.                  "IRIX" | "IRIX64" )
  981.                     cat /dev/null > $informix_dir/etc/.seuser
  982.                     ;;
  983.                 * )
  984.                     ;;
  985.             esac
  986.         fi
  987.     fi
  988.         
  989. }
  990.  
  991. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  992. #                        Start of postinstall_emd script
  993. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  994.  
  995. exit_code=0 ; export exit_code
  996.  
  997. PATH=/bin:/usr/bin:/etc:/usr/ucb:/usr/bsd:/usr/etc:$PATH ; export PATH
  998. app_name=`basename $0`
  999. temp_file=/tmp/$app_name.$$
  1000. ypcat_passwd_output=/tmp/$app_name.yp
  1001. ypcat_group_output=/tmp/$app_name.yg
  1002. niscat_passwd_output=/tmp/$app_name.np
  1003. niscat_group_output=/tmp/$app_name.ng
  1004.  
  1005. os_name=`uname -s`
  1006. os_release=`uname -r`
  1007.  
  1008. upgrade=0
  1009.  
  1010. #
  1011. # determine what ps options to use.
  1012. # All systems use "-e" expcept for
  1013. # SunOS 4.1.3 and 4.1.4 that use -auxww
  1014. #
  1015.  
  1016. ps_opts="-e"
  1017.  
  1018. if [ "$os_name" = "SunOS" ] ; then
  1019.     case "$os_release" in
  1020.         4.1.* )
  1021.             ps_opts="-auxww" ;;
  1022.         * ) ;;
  1023.     esac
  1024. fi
  1025.  
  1026. #
  1027. # Parse the command line arguments
  1028. #
  1029.  
  1030. while [ "$#" -ne 0 ] ; do
  1031.     case "$1" in
  1032.         -h* ) 
  1033.             display_usage
  1034.             exit 1
  1035.             ;;
  1036.         -f )
  1037.             informix_dir=$2
  1038.             shift
  1039.             ;;
  1040.         -emd* )
  1041.             emd_dir=$2
  1042.             shift
  1043.             ;;
  1044.         -dbhome )
  1045.             dbenl_home=$2
  1046.             shift
  1047.             ;;
  1048.         -v* )
  1049.             verbose_output="true"
  1050.             ;;
  1051.         -upgrade )
  1052.             upgrade=$2
  1053.             shift
  1054.             ;;
  1055.         * )
  1056.             echo $app_name: Invalid argument: $1 
  1057.             ;;
  1058.     esac
  1059.     shift
  1060. done
  1061.  
  1062. if [ -z "$emd_dir" ] ; then
  1063.     emd_dir=`fgrep 'emd_dir=' /etc/enlighten | cut '-d=' -f2`
  1064.     echo "$app_name: The EMD installation directory is defaulting to $emd_dir."
  1065. fi
  1066.  
  1067. if [ ! -d "$emd_dir" ] ; then
  1068.     echo "$app_name: The EMD installation directory '$emd_dir' was missing." 1>&2
  1069.     display_usage
  1070.     exit 2
  1071. fi
  1072.  
  1073. if [ -z "$informix_dir" ] ; then
  1074.     informix_dir=$emd_dir/informix
  1075. fi
  1076.  
  1077. if [ ! -d "$informix_dir" ] ; then
  1078.     echo "$app_name: The Informix directory '$informix_dir' was missing." 1>&2
  1079.     display_usage
  1080.     exit 2
  1081. fi
  1082.  
  1083. if [ -z "$dbenl_home" ] ; then
  1084.     dbenl_home=$emd_dir
  1085. fi
  1086.  
  1087.  
  1088. set_constants
  1089. add_informix_group
  1090. add_informix_user
  1091. add_dbenl_user
  1092. create_emd_database
  1093.  
  1094. rm -f $ypcat_passwd_output $ypcat_group_output \
  1095.     $niscat_passwd_output $niscat_group_output 2> /dev/null > /dev/null
  1096.  
  1097. exit $exit_code
  1098.